package com.zzh.lib.core.loader;


import android.content.Context;
import android.provider.MediaStore;
import android.text.TextUtils;

import com.zzh.lib.core.HLibrary;

import androidx.annotation.NonNull;
import androidx.loader.content.CursorLoader;

import static android.provider.MediaStore.MediaColumns.MIME_TYPE;

/**
 * Created by ZZH on 2023/2/1.
 *
 * @date: 2023/2/1 17:46
 * @email: zzh_hz@126.com
 * @author: zzh
 * @description: com.zzh.lib.core.loader
 */
public class HVideoLoader extends CursorLoader {
    private static final String[] VIDEO_PROJECTION = {
            //Base File
            MediaStore.Video.Media._ID,
            MediaStore.Video.Media.TITLE,
            MediaStore.Video.Media.DATA,
            MediaStore.Video.Media.SIZE,
            MediaStore.Video.Media.BUCKET_ID,
            MediaStore.Video.Media.BUCKET_DISPLAY_NAME,
            MediaStore.Video.Media.DATE_ADDED,
            //Video File
            MediaStore.Video.Media.DURATION,
            MediaStore.Video.Media.MIME_TYPE

    };

    public HVideoLoader(@NonNull Context context) {
        super(context);
        setProjection(VIDEO_PROJECTION);

        setUri(MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
        setSortOrder(MediaStore.Video.Media.DATE_ADDED + " DESC");

        if (TextUtils.isEmpty(HLibrary.getVideoSelection())) {
            setSelection(MIME_TYPE + "=? or " + MIME_TYPE + "=?");
        } else {
            setSelection(HLibrary.getVideoSelection());

        }

        if (HLibrary.getVideoSelectionArgs() == null) {
            setSelectionArgs(new String[]{"video/mpeg", "video/mp4"});
        } else {
            setSelectionArgs(HLibrary.getVideoSelectionArgs());
        }
    }
}
